package com.jason.www.dao;

import com.jason.www.domain.User;
import org.apache.ibatis.jdbc.SQL;

public class UserSqlProvider {

    public String insertSelective(User record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("user");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=BIGINT}");
        }
        
        if (record.getUserName() != null) {
            sql.VALUES("user_name", "#{userName,jdbcType=VARCHAR}");
        }
        
        if (record.getUserAge() != null) {
            sql.VALUES("user_age", "#{userAge,jdbcType=INTEGER}");
        }
        
        if (record.getUserSex() != null) {
            sql.VALUES("user_sex", "#{userSex,jdbcType=VARCHAR}");
        }
        
        if (record.getUserBirth() != null) {
            sql.VALUES("user_birth", "#{userBirth,jdbcType=DATE}");
        }
        
        if (record.getLoginName() != null) {
            sql.VALUES("login_name", "#{loginName,jdbcType=VARCHAR}");
        }
        
        if (record.getLoginPassword() != null) {
            sql.VALUES("login_password", "#{loginPassword,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(User record) {
        SQL sql = new SQL();
        sql.UPDATE("user");
        
        if (record.getUserName() != null) {
            sql.SET("user_name = #{userName,jdbcType=VARCHAR}");
        }
        
        if (record.getUserAge() != null) {
            sql.SET("user_age = #{userAge,jdbcType=INTEGER}");
        }
        
        if (record.getUserSex() != null) {
            sql.SET("user_sex = #{userSex,jdbcType=VARCHAR}");
        }
        
        if (record.getUserBirth() != null) {
            sql.SET("user_birth = #{userBirth,jdbcType=DATE}");
        }
        
        if (record.getLoginName() != null) {
            sql.SET("login_name = #{loginName,jdbcType=VARCHAR}");
        }
        
        if (record.getLoginPassword() != null) {
            sql.SET("login_password = #{loginPassword,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("id = #{id,jdbcType=BIGINT}");
        
        return sql.toString();
    }
}